//
//  DataCompareView.swift
//  MoyoungHome
//
//  Created by 李然 on 2022/9/28.
//

import UIKit
import SnapKit

open class BarRoundChartView: View {
    
    public var chartHeight:CGFloat = 200 {
        
        didSet {
            chartView.snp.updateConstraints { make in
                make.height.equalTo(chartHeight)
            }
        }
        
    }
    
    public lazy var titleLabel = Label()
    
    public lazy var subTitleLabel = Label()
    
    public lazy var chartView = DFBarChartView()
    
    public init() {
        super.init(frame: CGRect.zero)
    }
    
    public override init(frame: CGRect) {
        super.init(frame: frame)
    }
    
    public init(config: DFBarChartViewConfig, dataCompareAxisValueFormatter: DataCompareAxisValueFormatter) {
        super.init(frame: CGRect.zero)
        
        chartView.setConfig(config)
        chartView.setXAxis(valueFormatter: dataCompareAxisValueFormatter)
        
    }
    
    required public init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    open override func makeUI() {
        super.makeUI()
        
        addSubview(titleLabel)
        
        titleLabel.snp.makeConstraints { make in
            make.top.equalTo(20)
            make.leading.equalTo(26)
            
        }
        
        addSubview(subTitleLabel)
        subTitleLabel.snp.makeConstraints { make in
            make.top.equalTo(titleLabel.snp.bottom).offset(6)
            make.leading.equalTo(titleLabel)
        }
        
        addSubview(chartView)
        chartView.snp.makeConstraints { make in
            make.top.equalTo(subTitleLabel.snp.bottom).offset(20)
            make.height.equalTo(chartHeight)
            make.leading.equalTo(6)
            make.trailing.equalTo(-6)
            make.bottom.equalTo(-20)
        }
    }
    

}

